﻿cmake_minimum_required(VERSION 3.16)
#set(CMAKE_MODULE_PATH "D:/vcpkg/installed/x64-windows/share/ffmpeg")
project(JHPhoto_CMake VERSION 0.1 LANGUAGES CXX)

#add_subdirectory(MyToolbar)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Multimedia)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Multimedia)

add_subdirectory(MeasureView)
add_subdirectory(CameraCommon)
add_subdirectory(NosepieceCommon)
add_subdirectory(LampControl)
add_subdirectory(ImageProcessing)
add_subdirectory(Plugins/Camera/CameraHikVision)
#add_subdirectory(Plugins/Camera/CameraVisionKit)
#add_subdirectory(Plugins/Camera/CameraToupCam)
add_subdirectory(Plugins/Camera/CameraFluo)
#set(OpenCV_ROOT "${VCPKG_INSTALLED_DIR}/x64-windows/share/opencv4")
find_package(OpenCV REQUIRED)
add_library(qtOpenCV STATIC
    qtOpenCV/convert.h
    qtOpenCV/convert.cpp
)
target_link_libraries(qtOpenCV PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(qtOpenCV PUBLIC opencv_core opencv_imgproc)
target_include_directories(qtOpenCV PUBLIC ${PROJECT_SOURCE_DIR})

add_library(FocusMeasure STATIC
    AutoFocus/FocusMeasure.h
    AutoFocus/FocusMeasure.cpp
    AutoFocus/FocusMeasureObject.h
    AutoFocus/FocusMeasureObject.cpp
)

#target_link_libraries(FocusMeasure PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(FocusMeasure PRIVATE qtOpenCV)

set(TS_FILES JHPhoto_CMake_zh_CN.ts)

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        calibDialog.cpp
        calibDialog.h
        calibDialog.ui
        AboutDialog.h
        AboutDialog.cpp
        AboutDialog.ui
        app.rc
        ${TS_FILES}
        sndialog.cpp
        sndialog.ui
        sndialog.h
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(JHPhoto_CMake
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET JHPhoto_CMake APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation

    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(JHPhoto_CMake SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(JHPhoto_CMake
            ${PROJECT_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()


find_package(FFMPEG REQUIRED)
target_include_directories(JHPhoto_CMake PUBLIC ${FFMPEG_INCLUDE_DIRS})
target_link_directories(JHPhoto_CMake PUBLIC ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(JHPhoto_CMake PUBLIC ${FFMPEG_LIBRARIES})

target_link_libraries(JHPhoto_CMake PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(JHPhoto_CMake PRIVATE CameraCommon MeasureView NosepieceCommon)
target_link_libraries(JHPhoto_CMake PRIVATE FocusMeasure ImageProcessing)
target_link_libraries(JHPhoto_CMake INTERFACE NosepieceOUMIT)

target_include_directories(JHPhoto_CMake PRIVATE ${CMAKE_SOURCE_DIR})

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.JHPhoto_CMake)
endif()
set_target_properties(JHPhoto_CMake PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS JHPhoto_CMake
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(MSVC)
#    set_target_properties(JHPhoto_CMake PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
endif()


if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(JHPhoto_CMake)
endif()
